CREATE OR REPLACE FUNCTION public.get_indice(character varying, date)
  RETURNS numeric AS
$BODY$
-- Recibe un codigo de indice y una fecha, y devuelve el valor del indice mas proximo.
DECLARE
pCodValInd	ALIAS FOR $1;
pFecha		ALIAS FOR $2;
BEGIN
	RETURN ( select valorajuste from valindval where valindval.codvalind = pCodValInd and valindval.vigencia <= pFecha order by valindval.vigencia desc limit 1 );
END;
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;
ALTER FUNCTION public.get_indice(character varying, date) OWNER TO abacouser;



CREATE OR REPLACE FUNCTION public.get_indice(character varying, timestamp without time zone)
  RETURNS numeric AS
$BODY$
-- Recibe un codigo de indice y una fecha, y devuelve el valor del indice mas proximo.
DECLARE
pCodValInd	ALIAS FOR $1;
pFecha		ALIAS FOR $2;
BEGIN
	RETURN ( select get_indice(pCodValInd, cast(pFecha as date)) );
END;
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;
ALTER FUNCTION public.get_indice(character varying, timestamp without time zone) OWNER TO abacouser;




-- =====================================
SELECT aaversion('412.01');
-- =====================================
